<?php

/**
 * @author TungNS
 *
 */
class Menu {
	/**
	* Store menu items structure, each contains
	*	name: menu name, also css class name
	*	link: a.href value
	*	title: menu text
	*	use_language: if set to true, menu text value will be looked up on current language variable.
	*	target: a.target value
	*/
	/**
	 * @var unknown_type
	 */
	protected $_items = null;
	
	/**
	 * @var unknown_type
	 */
	protected $_options = null;
	
	/**
	 * @return unknown_type
	 */
	public function __construct() {
		$this->_items = Array();
	}

    /**
     * Returns the request object or request value
     * @itemsData: an array of menu items
     * @return TRUE if itemsData is a valid array
     */	
	/**
	 * @param $itemsData
	 * @return unknown_type
	 */
	public function setItems($itemsData) {
		if (is_array($itemsData)) {
			$this->_items = $itemsData;
			return TRUE;
		}
		else 
			return FALSE;
	}

	/**
	 * @param $name
	 * @param $value
	 * @return unknown_type
	 */
	public function setOption($name, $value) {
		$this->_options[$name] = $value;
	}
	
	/**
	 * @param $item
	 * @return unknown_type
	 */
	public function setActive($item) {
		$itemCount = count($this->_items);
		$isIndex = (is_int($item));
		
		for ($i=0; $i<$itemCount; $i++)  {
			$itm = &$this->_items[$i];
			
			if ($isIndex) 
				$itm['active'] = ($i == $item);
			else
				$itm['active'] = ($itm['name'] == $item);
		}

	}
	
	/**
	 * @return unknown_type
	 */
	public function getItems() {return $this->_items;}
	
	/**
	 * @return unknown_type
	 */
	public function getParams() {
		return array(
			'menuItems' => $this->_items,
			'options' => $this->_options
		);
	}
	
}

?>